<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml"
      xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>办理入职</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link rel="stylesheet" href="/dist/plugins/select2/select2.min.css">
    <link href="/dist/plugins/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/dist/plugins/webuploader-0.1.5/webuploader.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=84a6c1b54">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">

    <style type="text/css">
        td div {
            float: left;
            text-align: center;
            height: 100%;
        }

        td span {
            color: #2a8cec;
            padding: 0 6px;
        }

        td input {
            color: #2a8cec;
        }

        .table-detail {
            margin: 0 auto;
        }


        .table-detail select {
            text-indent: 0px !important;
        }

        .content {
            padding: 2px 8px;
        }

        .td-module{
            background: yellow !important;
            color: black;
        }
        .span-a-btn {
            position: absolute;
            right: 10px;
        }


    </style>
</head>
<body>
<iframe id="ifAttach" style="display:none"></iframe>
<section class="content" id="app" >
    <table class="table-detail">
        <tr class="td-title td-module">
            <td colspan="4">配置信息</td>
        </tr>
        <tr>
            <td class="td-title">模块名</td>
            <td class="td-tanZongStyle" style="width: 25%;">
                <input type="text" v-if="pageType=='edit'" v-model="config.name" class="validators"
                       placeholder="请输入"/>
                <span v-else style="text-align: center">{{config.name}}</span>
            </td>
            <td class="td-title">公司</td>
            <td class="td-tanZongStyle" style="width: 25%;">
                <span style="text-align: center;">{{config.companyName}}</span>
            </td>
        </tr>
        <tr>
            <td colspan="1" class="td-title td-module">字段名</td>
            <td colspan="3" class="td-title td-module">字段值
                    <span class="span-a-btn" v-if="pageType=='edit'">
                    <a href="javascript:void(0);" class="a-btn" @click="addRow()">添加一项</a>
                    <a href="javascript:void(0);" class="a-btn"  @click="delRow()">删除一项</a>
                    </span>
            </td>
        </tr>
        <tr v-for="(item,i) in extra">
            <td class="td-tanZongStyle"  >
                <input type="text" v-if="pageType=='edit'" v-model="item.title" class="validators"
                       placeholder="请输入信息名称"/>
                <span v-else>{{item.title}}</span>
            </td>
            <td colspan="3"  class="td-tanZongStyle">
                <input type="text" v-if="pageType=='edit'" v-model="item.value" class="validators"
                       placeholder="请输入默认值"/>
                <span v-else >{{item.value}}</span>
            </td>
        </tr>
    </table>
    <div style="height:30px;text-align: center;z-index:999;" v-if="pageType=='edit'">
        <input type="button" value="保存" @click="save()" class="btn oaBtn btn-sm" style="margin-top:5px;">
    </div>
</section>
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=602456c3"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=ff1c9bf8"></script>
<script type="text/javascript" src="/dist/plugins/select2/select2.min.js"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<!--ztree组件所需js-->
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.exhide-3.5.js"></script>
<script src="/dist/plugins/webuploader-0.1.5/webuploader.min.js"></script>

    <script type="text/javascript">

        var api = frameElement.api, W = api.opener;
        var app = new Vue({
        el: '#app',
        data: {
            name: $.wyui.page.urlParams.name ? $.wyui.page.urlParams.name : '',
            pageType:"edit",
            currentUser: getCurrentUser(),
            config:{
                "name":"",
                "config":"",
                "companyId":"",
                "companyName":"",
                "remark":"",
                "id":""
            },
            extra:[{"title":"","value":""}],//特殊字段
            goods:{
                main:{
                    id:'',
                    image:'',
                    createUserName:currentUser.name,
                    extra:''//特殊字段
                },
                attaches: []                //图片


            }
        },
        methods: {
            addRow:function () {
                var that = this;
                that.extra.push({"title":"","value":""});
            },
            delRow:function () {
                this.extra.splice(this.extra.length - 1, 1);
            },
            save:function () {
                api.close;
                var that=this;
                var newList=[];
                var remark=[]
                if(that.extra&&that.extra.length>0){
                    for(var i=0;i<that.extra.length;i++){
                        var data=that.extra[i];
                        if(data.title){
                            newList.push(data);
                            remark.push(data.title);
                        }
                    }
                    that.config.config=JSON.stringify(newList);
                    that.config.remark=remark.join(",");

                }else{
                    that.config.config='';
                    that.config.remark='';
                }
                if(that.name){
                    var w=window;
                    $.wyui.postMethod('/otherConfig/update.json', trimRN(that.config), function (data) {
                        console.log(data);
                        parent.app.getList();
                        parent.$(".ui_close").click();
                    });
                }else{
                    var w=window;
                    $.wyui.postMethod('/otherConfig/save.json', trimRN(that.config), function (data) {
                        console.log(data);
                        parent.app.getList();
                        parent.$(".ui_close").click();
                    });
                }

            },
            getDetail:function () {
                var that=this;
                $.wyui.postMethod('/otherConfig/getByName.json', {"name":that.name}, function (data) {
                    console.log(data);
                    that.extra=JSON.parse(data.config)
                    that.config=data;
                });
            }
        },
        mounted: function () {
            var that = this;
            if(!that.name){
                that.config.companyName=getCurrentUser().companyName;
                that.config.companyId=getCurrentUser().companyId;
            }else{
                this.getDetail();
            }
        }
    });
</script>

</body>
</html>